import ujson


def read_user(user_path):

    try:
        with open(user_path, 'r', encoding='utf-8') as f:
            content = ujson.load(f)
        return content
    except FileNotFoundError:
        print(f"错误：文件 {user_path} 不存在")
        return None
    except ujson.JSONDecodeError:
        print(f"错误：文件 {user_path} 格式不正确（非 valid JSON）")
        return None
    except Exception as e:
        print(f"读取文件 {user_path} 失败：{str(e)}")
        return None

def write_user(user_path, data):
    try:
        with open(user_path, 'w', encoding='utf-8') as f:
            ujson.dump(data, f)
        return True
    except TypeError as e:
        print(f"错误：数据无法序列化（可能包含不可 JSON 序列化的类型）：{str(e)}")
        return False
    except Exception as e:
        print(f"写入文件 {user_path} 失败：{str(e)}")
        return False

user_path = "/sdcard/test.json"

data = [
   {"刘承涛":"6103", 
      "李岩俊": "3716rhfav", 
      "未到": [
         "张伟强", "王芳婷", "李军辉", "陈秀英", 
         "刘洋波", "赵凯敏", "黄亮静", "周佳伟", 
         "吴娜杰", "徐勇娟", "孙秀英", "马亮霞", 
         "朱婷辉", "胡洋敏", "林佳军", "郭艳磊", 
         "何芳强", "高慧明", "罗琳刚", "郑婷健", 
         "梁秀英", "谢洋亮", "宋佳飞", "唐敏凯", 
         "许芳辉", "韩勇静", "冯杰波", "邓婷宁", 
         "曹亮兵", "彭洋旭", "曾芳波", "肖敏宁", 
         "田佳勇", "董艳刚", "潘秀英", "袁亮健", 
         "蔡婷辉", "蒋洋敏", "余佳军", "于芳强", 
         "杜慧明", "叶琳刚", "程婷健", "魏秀英", 
         "苏洋亮", "吕佳飞", "丁敏凯"]},
     {"刘承涛":"6103", 
      "李岩俊": "3716rhfav", 
      "未到": [
         "张伟强", "王芳婷", "李军辉", "陈秀英", 
         "刘洋波", "赵凯敏", "黄亮静", "周佳伟", 
         "吴娜杰", "徐勇娟", "孙秀英", "马亮霞", 
         "朱婷辉", "胡洋敏", "林佳军", "郭艳磊", 
         "何芳强", "高慧明", "罗琳刚", "郑婷健", 
         "梁秀英", "谢洋亮", "宋佳飞", "唐敏凯", 
         "许芳辉", "韩勇静", "冯杰波", "邓婷宁", 
         "曹亮兵", "彭洋旭", "曾芳波", "肖敏宁", 
         "田佳勇", "董艳刚", "潘秀英", "袁亮健", 
         "蔡婷辉", "蒋洋敏", "余佳军", "于芳强", 
         "杜慧明", "叶琳刚", "程婷健", "魏秀英", 
         "苏洋亮", "吕佳飞", "丁敏凯"]}
     ]
#data = {"短信中心" : ["+8613800393500", 1],"class" : "教务处","phone" : ["18203600458", "13949067045"],"century":"20世纪","ip" : "192.168.2"}

write_user(user_path, data)

result = read_user(user_path)

print(result)


print(result['century'])

print(result['短信中心'])